from typing import List


class Solution:
    def assignBikes(self, workers: List[List[int]], bikes: List[List[int]]) -> List[int]:
        s1, s2 = len(workers), len(bikes)

        distances = []

        for i in range(s1):
            for j in range(s2):
                distance = abs(workers[i][0] - bikes[j][0]) + abs(workers[i][1] - bikes[j][1])
                distances.append([distance, i, j])

        waiting = s1  # 等待人数
        bikes_stat = [True] * s2  # 自行车被占用的状态
        ans = [-1] * s1

        for distance, i, j in sorted(distances):
            if ans[i] == -1 and bikes_stat[j] is True:
                ans[i] = j
                waiting -= 1
                bikes_stat[j] = False
            if waiting == 0:
                break

        return ans


if __name__ == "__main__":
    print(Solution().assignBikes(workers=[[0, 0], [2, 1]], bikes=[[1, 2], [3, 3]]))  # [1,0]
    print(Solution().assignBikes(workers=[[0, 0], [1, 1], [2, 0]], bikes=[[1, 0], [2, 2], [2, 1]]))  # [0,2,1]
